package com.anhuanjia.tools.eao.controller;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.util.StringUtils;

import com.anhuanjia.tools.eao.bean.CrmCompany;
import com.anhuanjia.tools.eao.bean.EaoAppraise;
import com.anhuanjia.tools.eao.bean.EaoBuildingContent;
import com.anhuanjia.tools.eao.bean.EaoDataBill;
import com.anhuanjia.tools.eao.bean.EaoProductionEquipment;
import com.anhuanjia.tools.eao.bean.EaoProjectDoc;
import com.anhuanjia.tools.eao.bean.EaoProjectInfo;
import com.anhuanjia.tools.eao.bean.EaoProjectInfo2;
import com.anhuanjia.tools.eao.bean.EaoProjectStaff;
import com.anhuanjia.tools.eao.bean.EaoPublicProject;
import com.anhuanjia.tools.eao.bean.EaoPublicityQuestions;
import com.anhuanjia.tools.eao.bean.EaoPublicityURL;
import com.anhuanjia.tools.eao.bean.EaoSensitivePoints;
import com.anhuanjia.tools.eao.bean.EaoSubmitTime;
import com.anhuanjia.tools.eao.bean.EaoSurroundCompany;
import com.anhuanjia.tools.eao.beanvo.EaoProjectInfoVo;
import com.anhuanjia.tools.eao.util.FindDateUtil;
import com.anhuanjia.tools.eao.util.GBTUtil;
import com.anhuanjia.tools.eao.util.GetLatAndLng;
import com.anhuanjia.tools.eao.util.ProcedureUtils;
import com.efastsoft.framework.Member;
import com.efastsoft.framework.UIFacade;
import com.efastsoft.framework.UserInfo;
import com.efastsoft.framework.annotation.Alias;
import com.efastsoft.framework.annotation.Priv;
import com.efastsoft.framework.annotation.Priv.LoginType;
import com.efastsoft.framework.data.DataRow;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;
import com.efastsoft.framework.data.Transaction;
import com.efastsoft.framework.utility.StringUtil;

/**
 *
 * @ClassName: ProjectInformationUI
 * @Description: 对项目信息表以及项目文件表进行操作
 * @author wangqiangqiang
 * @date 2018年9月17日下午4:40:20
 * 
 */
@Alias(value = "projectInformation")
public class ProjectInformationUI extends UIFacade {

	private final static int[] li_SecPosValue = { 1601, 1637, 1833, 2078, 2274, 2302, 2433, 2594, 2787, 3106, 3212,
			3472, 3635, 3722, 3730, 3858, 4027, 4086, 4390, 4558, 4684, 4925, 5249, 5590 };
	private final static String[] lc_FirstLetter = { "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N",
			"O", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z" };

	/**
	 * 查询报告书、报告表数量， 项目绩效，查询项目库数据
	 */
	@Priv(loginType = LoginType.Member)
	public void findProject() {

		Long dataTable = new Q(" select company from Mh_Resource where Member = ? ", Member.getUID()).executeLong();
		if (!StringUtils.isEmpty(dataTable) || "Ent".equals(Member.getType())) {
			Map<String, Integer> map = new HashMap<String, Integer>();
			// 查询报告书、报告表数量
			int reportNum = 0;
			int reportTableNum = 0;
			int contractAmount = 0;
			Q qq1 = new Q(
					"select count(1) as num from eao_project_info where ReportType = '报告书'  and PerjectType = 16");
			Q qq2 = new Q(
					"select count(1) as num from eao_project_info where ReportType = '报告表'  and PerjectType = 16");
			Q projectDt2 = new Q("select sum(ContractAmount) as num from eao_project_info where PerjectType = 16");
			Q q = new Q("select * from eao_project_info where 1 = 1 and PerjectType = 16");
			Q q2 = new Q("select count(1) as num from eao_project_info where 1 = 1 and PerjectType = 16");
			if ("Ent".equals(Member.getType())) {
				qq1.append(" and Company = ?", Member.getCompany());
				q.append(" and Company = ?", Member.getCompany());
				q2.append(" and Company = ?", Member.getCompany());
				qq2.append(" and Company = ?", Member.getCompany());
				projectDt2.append(" and Company = ?", Member.getCompany());
			} else {
				q.append(" and Company = ?", dataTable);
				q2.append(" and Company = ?", dataTable);
				qq1.append(" and Company = ?", dataTable);
				qq2.append(" and Company = ?", dataTable);
				projectDt2.append(" and Company = ?", dataTable);
			}
			DataTable dt1 = qq1.fetch();
			if (!StringUtils.isEmpty(dt1.get(0))) {
				for (DataRow dataRow : dt1) {
					reportNum = dataRow.getInt("num");
				}
				map.put("reportNum", reportNum);// 报告书
			} else {
				$F("查询报告书数量失败");
			}

			DataTable dt2 = qq2.fetch();
			if (!StringUtils.isEmpty(dt2.get(0))) {
				for (DataRow dataRow : dt2) {
					reportTableNum = dataRow.getInt("num");
				}
				map.put("reportTableNum", reportTableNum);// 报告表
			} else {
				$F("查询报告表数量失败");
			}

			DataTable projectDt = projectDt2.fetch();
			if (!StringUtils.isEmpty(projectDt.get(0))) {
				for (DataRow dataRow : projectDt) {
					contractAmount = dataRow.getInt("num");
				}
				map.put("contractAmount", contractAmount);// 绩效
			} else {
				$F("查询绩效失败");
			}

			// 查询项目库数据
			int proNum = 0;
			int pageSize = this.Request.getInt("PageSize");
			if (pageSize == 0) {
				pageSize = 10;
			}
			int pageIndex = this.Request.getInt("PageIndex");
			String searchProject = $V("SearchProject");

			if (StringUtil.isNotEmpty(searchProject)) {
				q.and().like("ProjectName", searchProject);
				q2.and().like("ProjectName", searchProject);
			}
			q.append(" order by EntTime desc,PerjectTime desc ");
			DataTable project = q.fetch(pageSize, pageIndex);
			DataTable projectNum = q2.fetch();
			List<EaoProjectInfoVo> projectInfoVoList = new ArrayList<EaoProjectInfoVo>();
			if (project.getRowCount() > 0) {
				for (DataRow dataRow : project) {
					EaoProjectInfoVo rojectInfoVo = new EaoProjectInfoVo();
					rojectInfoVo.setId(dataRow.getString("Id"));
					rojectInfoVo.setProjectName(dataRow.getString("ProjectName"));
					rojectInfoVo.setBuildAddress(dataRow.getString("BuildAddress"));
					rojectInfoVo.setReportType(dataRow.getString("ReportType"));
					rojectInfoVo.setPerjectTime(dataRow.getString("PerjectTime"));
					rojectInfoVo.setEntTime(dataRow.getString("EntTime"));
					rojectInfoVo.setContractAmount(dataRow.getString("ContractAmount"));
					String perject_leader = new Q("select RealName from Ec_Member where ID = ?",
							dataRow.getString("PerjectLeader")).executeString();
					rojectInfoVo.setPerjectLeader(perject_leader);
					rojectInfoVo.setBuildUnit(dataRow.getString("BuildUnit"));
					rojectInfoVo.setUserName(dataRow.getString("CreatePerson"));
					DataTable company = new Q("select FullName from Crm_Company where Id = ?", Member.getCompany())
							.fetch();
					rojectInfoVo.setFullName(company.getString(0, 0));
					projectInfoVoList.add(rojectInfoVo);

				}
				if (projectInfoVoList.isEmpty()) {
					projectInfoVoList = null;
				}
				this.Response.put("projectList", projectInfoVoList);
			} else {
				$F("查询项目记录失败");
			}
			// 查询项目总数
			if (projectNum.getRowCount() != 0) {
				for (DataRow dataRow : projectNum) {
					proNum = dataRow.getInt("num");
				}
				map.put("proNum", proNum);// 项目总数
				$S("map", map);//
			} else {
				map.put("contractAmount", 0);
				map.put("reportTableNum", 0);
				map.put("reportNum", 0);// 报告书
				this.Response.put("map", map);
				f("没有查询到数据");
			}
		} else {
			$F("查询项目总数失败");
		}
	}

	/**
	 * 谷歌地图具体位置
	 * 
	 * @throws Exception
	 */
	@Priv(loginType = LoginType.Member)
	public void findProjectToMap() throws Exception {
		String mProvince = $V("MProvince");
		String mCity = $V("MCity");
		String report_type = $V("ReportType");
		Long dataTable = new Q(" select company from Mh_Resource where Member = ? ", Member.getUID()).executeLong();
		if (!StringUtils.isEmpty(dataTable)) {
			Q q = new Q("select id,ProjectCoordinates from eao_project_info where 1 = 1 and PerjectType = 16");
			if ("Ent".equals(Member.getType())) {
				q.append(" and Company = ?", Member.getUID());
			} else {
				q.append(" and Company = ?", dataTable);
			}
			if (StringUtil.isNotEmpty(mProvince) && StringUtil.isEmpty(mCity)) {
				Map<String, Object> map = GetLatAndLng.getGoogleLatLng(mProvince);
				String lng = map.get("lng").toString().substring(0, map.get("lng").toString().lastIndexOf('.'));
				String lat = map.get("lat").toString().substring(0, map.get("lat").toString().lastIndexOf('.'));
				q.append(" and ProjectCoordinates like ?", "%" + lat + "%" + "," + "%" + lng + "%");
			}
			if (StringUtil.isNotEmpty(mProvince) && StringUtil.isNotEmpty(mCity)) {
				Map<String, Object> map = GetLatAndLng.getGoogleLatLng(mProvince + mCity);
				String lng = map.get("lng").toString().substring(0, map.get("lng").toString().lastIndexOf('.'));
				String lat = map.get("lat").toString().substring(0, map.get("lat").toString().lastIndexOf('.'));
				q.append(" and ProjectCoordinates like ?", "%" + lat + "%" + "," + "%" + lng + "%");
			}
			if (StringUtil.isNotEmpty(report_type)) {
				q.append(" and ReportType = ?", report_type);
			}
			DataTable project = q.fetch();
			List<Map<String, String>> list = new ArrayList<>();
			List<List<Map<String, Object>>> list1 = new ArrayList<>();
			if (project.getRowCount() > 0) {
				for (DataRow dataRow : project) {
					String[] latLng = dataRow.getString("ProjectCoordinates").split(",");
					if (latLng.length == 2) {
						Map<String, String> map = new HashMap<>();
						map.put("id", dataRow.getString("id"));
						map.put("lat", latLng[0]);
						map.put("lng", latLng[1]);
						list.add(map);
					} else if (latLng.length == 4) {
						List<Map<String, Object>> lists = new ArrayList<>();
						Map<String, Object> map = new HashMap<>();
						map.put("id", dataRow.getString("id"));
						map.put("lat", Double.parseDouble(latLng[0]));
						map.put("lng", Double.parseDouble(latLng[1]));
						lists.add(map);
						Map<String, Object> map1 = new HashMap<>();
						map1.put("id", dataRow.getString("id"));
						map1.put("lat", Double.parseDouble(latLng[2]));
						map1.put("lng", Double.parseDouble(latLng[3]));
						lists.add(map);
						lists.add(map1);
						list1.add(lists);
					}
				}
			} else {
				$F("查询项目记录失败");
			}
			this.Response.put("mapList", list);
			this.Response.put("mapList1", list1);
		} else {
			$F("查询项目记录失败");
			List<Map<String, String>> list = new ArrayList<>();
			Map<String, String> map = new HashMap<>();
			map.put("id", "");
			map.put("lat", "");
			map.put("lng", "");
			list.add(map);
			this.Response.put("mapList", list);
		}
	}

	/**
	 * 谷歌地图弹窗信息
	 */
	@Priv(loginType = LoginType.Member)
	public void mapInfo() {
		String id = $V("Id");
		DataTable dt = new Q("select * from eao_project_info where Id = ?", id).fetch();
		if (dt.getRowCount() != 0) {
			EaoProjectInfo pi = new EaoProjectInfo();
			pi.setValue(dt.get(0));
			this.Response.put("projectInfo", pi);
			s("查询成功");
		} else {
			f("查询失败");
		}
	}

	/**
	 * @Title: saveOrUpdateProject
	 * @Description: 保存或者添加项目
	 * @author wangqiangqiang
	 * @throws SecurityException
	 * @throws NoSuchMethodException
	 * @throws InvocationTargetException
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @date 2018年9月17日下午4:39:22
	 */
	@Priv(loginType = LoginType.Member)
	public void saveOrUpdateProject() throws NoSuchMethodException, SecurityException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException {
		Date data = new Date();
		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Transaction transaction = new Transaction();
		Integer project_state = 1;
		Integer btn_way = Integer.valueOf($V("BtnWay"));// 提交方式
		// 定义项目实体类对象
		EaoProjectInfo projectInfo = new EaoProjectInfo();
		projectInfo.setValue(this.Request);
		String id = projectInfo.getId();
		String table = new Q(" select IsEngineer from eao_is_engineer where Member = ? ", Member.getUID())
				.executeString();
		String table1 = new Q(" select ParentId from eao_position where Id = ? ", table).executeString();
		if (StringUtil.isNotEmpty(table1)) {
			table = table1;
		}
		if (StringUtil.isNotEmpty(id)) {
			DataTable dt = new Q("select * from eao_project_info where Id= ? ", id).fetch();
			if (dt.getRowCount() != 0) {
				if (dt.getInt(0, "PerjectType") > 1 && table.equals("8")) {
					f("你无权进行此操作，请继续关注项目进度，若要推进项目进度，请联系项目负责人及项目组成员");
					return;
				}
			} else {
				f("你操作的项目不存在");
				return;
			}
		}
		// 判断项目id是否存在
		if (StringUtils.isEmpty(id)) {
			if (StringUtils.isEmpty(projectInfo.getProjectName()) || StringUtils.isEmpty(projectInfo.getBuildUnit())
					|| StringUtils.isEmpty(projectInfo.getLinkman())
					|| StringUtils.isEmpty(projectInfo.getTelNumber())) {
				f("请填写信息完善再提交");
				return;
			}
			ProjectInformationUI informationUI = new ProjectInformationUI();
			if (!informationUI.getProjectName()) {
				f("项目名已存在,请更换新的项目名");
				return;
			}
			if (!StringUtils.isEmpty(table) || "Ent".equals(Member.getType())) {
				String IsEngineer = new Q(" select ParentId from eao_Position where Id = ? ", table).executeString();
				if (StringUtil.isNotEmpty(IsEngineer)) {
					table = IsEngineer;
				}
				projectInfo.setId(UUID.randomUUID().toString());
				// 获得项目编号
				String ProjectNumber = informationUI.getProjectNumber();
				if (!StringUtils.isEmpty(ProjectNumber)) {
					projectInfo.setProjectNumber(ProjectNumber);
				}
				projectInfo.setPerjectTime(new Date());
				projectInfo.setFile("0");
				projectInfo.setCreatePerson(UserInfo.getID().intValue());
				String tof = null;
				String compType = "";
				if ("Ent".equals(Member.getType())) {
					projectInfo.setCompany(UserInfo.getID().toString());
					projectInfo.setBranchInnerCode(Member.getBranchInnerCode());
					// 项目级别
					DataTable dt = new Q(
							"select CompanyType , Id from Mh_Branch where Company = ? and ParentInnerCode = '0'",
							UserInfo.getID().toString()).fetch();
					for (DataRow drtof : dt) {
						compType = drtof.getString(0);
						DataTable dt2 = new Q("select Tof from eao_tof where BranchId = ? and CompanyId = ?",
								drtof.get(1), Member.getCompany()).fetch();
						if (dt2.getRowCount() != 0) {
							tof = dt2.getString(0, 0);
						}
					}
				} else {
					DataTable dataTable = new Q("select Company , BranchInnerCode from Mh_Resource where Member = ? ",
							Member.getUID()).fetch();
					projectInfo.setCompany(dataTable.get(0, 0).toString());
					// 项目级别
					DataTable dt = new Q(
							"select CompanyType , BranchInnerCode , ParentInnerCode , id from Mh_Branch where Company = ? and BranchInnerCode = ?",
							dataTable.get(0, 0), dataTable.get(0, 1)).fetch();
					for (DataRow drtof : dt) {
						if ("2".equals(dt.get(0, 0))) {
							DataTable dt1 = new Q(
									"select CompanyType , id from Mh_Branch where BranchInnerCode = ? and Company = ?",
									drtof.get(2), dataTable.get(0, 0)).fetch();
							compType = dt1.getString(0, 0);
							projectInfo.setBranchInnerCode(dt.get(0, 2).toString());
							DataTable dt2 = new Q("select Tof from eao_tof where BranchId = ? and CompanyId = ?",
									drtof.get(2), Member.getCompany()).fetch();
							if (dt2.getRowCount() != 0) {
								tof = dt2.getString(0, 0);
							}
						} else {
							compType = drtof.getString(0);
							projectInfo.setBranchInnerCode(dt.get(0, 1).toString());
							DataTable dt2 = new Q("select Tof from eao_tof where BranchId = ? and CompanyId = ?",
									drtof.get(1), Member.getCompany()).fetch();
							if (dt2.getRowCount() != 0) {
								tof = dt2.getString(0, 0);
							}
						}
					}
				}
				if ("1".equals(compType)) {
					projectInfo.setProjectLevel("1");
					if (StringUtils.isEmpty(tof)) {
						// 1默认分公司为5审
						projectInfo.setTof("1");
					} else {
						projectInfo.setTof(tof);
					}
				} else {
					projectInfo.setProjectLevel("0");
					if (StringUtils.isEmpty(tof)) {
						// 1默认总公司为3审
						projectInfo.setTof("0");
					} else {
						projectInfo.setTof(tof);
					}
				}
				projectInfo.setIsHide("0");// 新增默认为0
				if (btn_way == ProcedureUtils.BTN_SAVE) {
					projectInfo.setPerjectType(project_state);// 创建项目
					EaoSubmitTime submitTime = new EaoSubmitTime();
					submitTime.setId(UUID.randomUUID().toString());
					submitTime.setProjectId(projectInfo.getId());
					submitTime.setProjectType("0");
					submitTime.setSubmitType("0");
					String dates = sd.format(data);
					submitTime.setDataTime(dates);
					submitTime.setOperate(Member.getRealName());
					transaction.insert(submitTime);
				} else if (btn_way == ProcedureUtils.BTN_SUBMIT) {
					projectInfo.setIsAssign("0");
					if ("1".equals(compType)) {
						projectInfo.setIsFcAssign("0");
					} else if ("0".equals(compType)) {
						projectInfo.setIsFcAssign("1");
					}
					this.Response.put("compType", compType);
					projectInfo.setPerjectType(project_state);// 资料收集
					EaoSubmitTime submitTime = new EaoSubmitTime();
					submitTime.setId(UUID.randomUUID().toString());
					submitTime.setProjectId(projectInfo.getId());
					submitTime.setProjectType("0");
					submitTime.setSubmitType("1");
					String dates = sd.format(data);
					submitTime.setDataTime(dates);
					submitTime.setOperate(Member.getRealName());
					transaction.insert(submitTime);
				}
				// 定义项目文件类对象
				EaoProjectDoc projectDoc = new EaoProjectDoc();
				projectDoc.setAuditData("");
				projectDoc.setValue(this.Request);
				projectDoc.setId(UUID.randomUUID().toString());
				projectDoc.setProjectId(projectInfo.getId());
				for (int i = 0; i < 21; i++) {
					EaoDataBill dataBill = new EaoDataBill();
					dataBill.setId(UUID.randomUUID().toString());
					dataBill.setProjectId(projectInfo.getId());
					dataBill.setProjectDataName(i + "");
					dataBill.setDataStock("0");
					transaction.insert(dataBill);
				}
				transaction.insert(projectInfo);
				transaction.insert(projectDoc);
				if (transaction.commit()) {
					this.Response.put("projectId", projectInfo.getId());
					s("创建项目成功");
				} else {
					f("创建项目失败");
				}
			} else {
				f("没有创建项目权限，请联系管理员分配权限");
			}
		} else {
			// id存在,进行修改操作
			DataTable dt = new Q("select *  from eao_project_info where Id= ? ", id).fetch();
			boolean flag = false;
			boolean flag2 = false;
			if (dt.getRowCount() != 0) {
				EaoProjectInfo projectInfoUpdate = new EaoProjectInfo();
				projectInfoUpdate.setValue(dt.get(0));// 数据库的值
				String ReportChapter = projectInfoUpdate.getReportChapter();
				String EconomyIndustryType = projectInfoUpdate.getEconomyIndustryType();
				if (projectInfo.getPerjectType() > 2) {
					int cont = new Q(" select count(*) from eao_report_chapter where Type = ?",
							projectInfo.getReportType()).executeInt();
					DataTable chapter = new Q(" select * from eao_project_staff where ProjectId = ? ", id).fetch();
					int cuont = 0;
					if (StringUtil.isNotEmpty(projectInfoUpdate.getReportChapter())) {
						switch (projectInfoUpdate.getReportChapter().split("\"").length) {
						case 3:
							cuont = cuont + 1;
							break;
						case 5:
							cuont = cuont + 2;
							break;
						case 7:
							cuont = cuont + 3;
							break;
						case 9:
							cuont = cuont + 4;
							break;
						case 11:
							cuont = cuont + 5;
							break;
						case 13:
							cuont = cuont + 6;
							break;
						case 15:
							cuont = cuont + 7;
							break;
						case 17:
							cuont = cuont + 8;
							break;
						case 19:
							cuont = cuont + 9;
							break;
						case 21:
							cuont = cuont + 10;
							break;
						case 23:
							cuont = cuont + 11;
							break;
						case 25:
							cuont = cuont + 12;
							break;
						default:
							cuont = cuont + 0;
						}
					}
					for (DataRow dataRow : chapter) {
						EaoProjectStaff staff = new EaoProjectStaff();
						staff.setValue(dataRow);
						if (StringUtil.isNotEmpty(staff.getReportChapter())) {
							switch (staff.getReportChapter().split("\"").length) {
							case 3:
								cuont = cuont + 1;
								break;
							case 5:
								cuont = cuont + 2;
								break;
							case 7:
								cuont = cuont + 3;
								break;
							case 9:
								cuont = cuont + 4;
								break;
							case 11:
								cuont = cuont + 5;
								break;
							case 13:
								cuont = cuont + 6;
								break;
							case 15:
								cuont = cuont + 7;
								break;
							case 17:
								cuont = cuont + 8;
								break;
							case 19:
								cuont = cuont + 9;
								break;
							case 21:
								cuont = cuont + 10;
								break;
							case 23:
								cuont = cuont + 11;
								break;
							case 25:
								cuont = cuont + 12;
								break;
							default:
								cuont = cuont + 0;
							}
						}
					}
					this.Response.put("cont", cont);
					this.Response.put("cuont", cuont);
					if (cont != cuont) {
						f("请进入资料收集环节对项目组成员负责专项重新分配完全");
						return;
					}
				}
				String projectNumber = projectInfoUpdate.getProjectNumber();// 获取项目编号
				// 判断有无更改是否留痕
				EaoProjectInfo2 projectInfo23 = new EaoProjectInfo2();
				projectInfo23.setValue(dt.get(0));// 接收的值
				EaoProjectInfo2 projectInfo24 = new EaoProjectInfo2();
				projectInfo24.setValue(this.Request);// 接收的值
				flag = compare(projectInfo23, projectInfo24);
				projectInfoUpdate.setValue(this.Request);
				if (!"8".equals(table) && StringUtil.isNotEmpty(table) && "1".equals(projectInfoUpdate.getIsAssign())) {
					Boolean bl = true;
					if (this.Request.getInt("PerjectType") != 15 && "7".equals(table)) {
						bl = false;
					}
					if (bl) {
						String economy_industry_type = projectInfoUpdate.getEconomyIndustryType();
						EaoProjectInfo projectInfoUpdate2 = new EaoProjectInfo();
						projectInfoUpdate2.setValue(this.Request);// 接收的值
						if ("2".equals(projectInfoUpdate.getPerjectType().toString())) {
							projectInfoUpdate.setReportChapter(ReportChapter);
							String Report_type = this.$V("ReportType");
							DataTable perjecte = new Q(
									" select Tid , Item from eao_report_type where ReportId = ? or Item = ?",
									Report_type, Report_type).fetch();
							projectInfoUpdate.setReportType(perjecte.getString(0, 1));
						}
						if ("3".equals(projectInfoUpdate.getPerjectType().toString())) {
							projectInfoUpdate.setEconomyIndustryType(economy_industry_type);
						}
						project_state = dt.get(0).getInt("PerjectType");
						if (this.Request.getInt("PerjectType") < project_state) {
							projectInfoUpdate.setPerjectType(project_state);
							projectInfoUpdate2.setPerjectType(project_state);
						} else {
							if (btn_way == ProcedureUtils.BTN_SUBMIT) {
								if (this.Request.getInt("PerjectType") == 5) {
									if (projectInfoUpdate.getTof().equals("0")) {
										project_state = 8;
										projectInfoUpdate.setPerjectType(project_state);
									} else {
										project_state += 1;
										projectInfoUpdate.setPerjectType(project_state);
									}
								} else {
									if (this.Request.getInt("PerjectType") == 15) {
										if ("1".equals(this.Request.getString("UserOrg"))) {
											project_state += 1;
											projectInfoUpdate.setPerjectType(project_state);
										} else {
											projectInfoUpdate.setPerjectType(15);
										}
									} else {
										project_state += 1;
										projectInfoUpdate.setPerjectType(project_state);
									}
								}
							}
						}
						// 最后一个流程
						if (this.Request.getInt("PerjectType") == 15) {
							if (btn_way == ProcedureUtils.BTN_SUBMIT) {
								projectInfoUpdate.setEntTime(new Date());
							}
						}

						// 添加submitTime表的数据
						Integer ptype = this.Request.getInt("PerjectType");
						String ptypes = null;
						if (ptype < 6 | ptype > 10) {
							if (ptype < 16) {
								if (btn_way == ProcedureUtils.BTN_SUBMIT) {
									EaoSubmitTime submitTime = new EaoSubmitTime();
									submitTime.setId(UUID.randomUUID().toString());
									submitTime.setProjectId(id);
									if (ptype < 6) {
										ptypes = ptype - 1 + "";
									} else {
										ptypes = ptype - 6 + "";
									}
									submitTime.setProjectType(ptypes);
									submitTime.setSubmitType("1");
									String dates = sd.format(data);
									submitTime.setDataTime(dates);
									submitTime.setOperate(Member.getRealName());
									transaction.insert(submitTime);
								} else {

									EaoSubmitTime submitTime = new EaoSubmitTime();
									submitTime.setId(UUID.randomUUID().toString());
									submitTime.setProjectId(id);
									if (ptype < 6) {
										ptypes = ptype - 1 + "";
									} else {
										ptypes = ptype - 6 + "";
									}
									submitTime.setProjectType(ptypes);
									submitTime.setSubmitType("0");
									String dates = sd.format(data);
									submitTime.setDataTime(dates);
									submitTime.setOperate(Member.getRealName());
									transaction.insert(submitTime);
								}
							}
						}
						if (this.Request.getInt("PerjectType") != 2) {
							projectInfoUpdate.setEconomyIndustryType(EconomyIndustryType);
						}
						transaction.update(projectInfoUpdate);
						EaoProjectInfo2 projectInfo2 = new EaoProjectInfo2();
						if (flag == true) {// 对项目基础表和资料表有值的字段进行修改时才执行备份
							DataTable dt3 = new Q("select * from eao_project_info2 where ProjectNumber = ? ",
									projectNumber).fetch();
							projectInfo2.setValue(dt.get(0));
							Boolean flag3 = true;
							Boolean flag4 = false;
							if (dt3.getRowCount() != 0) {
								for (DataRow dataRow : dt3) {
									EaoProjectInfo2 projectInfo22 = new EaoProjectInfo2();
									projectInfo22.setValue(dataRow);
									flag2 = compare(projectInfo2, projectInfo22);
									if (flag2) {
										flag4 = true;
									}
								}
								if (!flag4) {
									flag3 = false;
								}
							}
							if (flag3) {
								projectInfo2.setProjectNumber(projectNumber);
								projectInfo2.setOperator(Member.getRealName());
								projectInfo2.setUpdateTime(new Date());
								projectInfo2.setId(UUID.randomUUID().toString());
								transaction.insert(projectInfo2);
							}
						}
						if (btn_way == ProcedureUtils.BTN_SUBMIT) {
							if (transaction.commit()) {
								this.Response.put("projectId", projectInfo.getId());
								s("项目提交成功");
							} else {
								f("项目提交失败");
							}
						} else {
							if (transaction.commit()) {
								this.Response.put("projectId", projectInfo.getId());
								s("保存项目成功");
							} else {
								f("保存项目失败");
							}
						}
					} else {
						f("无权限进行此操作");
					}
				} else if (("8".equals(table) && 1 == projectInfoUpdate.getPerjectType())
						|| (Member.getUID() == projectInfoUpdate.getCreatePerson()
								&& 1 == projectInfoUpdate.getPerjectType())) {
					if (btn_way == ProcedureUtils.BTN_SAVE) {
						projectInfoUpdate.setValue(this.Request);
						projectInfoUpdate.setPerjectType(project_state);// 创建项目
						EaoSubmitTime submitTime = new EaoSubmitTime();
						submitTime.setId(UUID.randomUUID().toString());
						submitTime.setProjectId(projectInfo.getId());
						submitTime.setProjectType("0");
						submitTime.setSubmitType("0");
						String dates = sd.format(data);
						submitTime.setDataTime(dates);
						submitTime.setOperate(Member.getRealName());
						transaction.update(projectInfoUpdate);
						transaction.insert(submitTime);

						EaoProjectInfo2 projectInfo2 = new EaoProjectInfo2();
						if (flag == true) {// 对项目基础表和资料表有值的字段进行修改时才执行备份
							DataTable dt3 = new Q("select * from eao_project_info2 where ProjectNumber = ? ",
									projectNumber).fetch();
							projectInfo2.setValue(dt.get(0));
							Boolean flag3 = true;
							Boolean flag4 = false;
							if (dt3.getRowCount() != 0) {
								for (DataRow dataRow : dt3) {
									EaoProjectInfo2 projectInfo22 = new EaoProjectInfo2();
									projectInfo22.setValue(dataRow);
									flag2 = compare(projectInfo2, projectInfo22);
									if (flag2) {
										flag4 = true;
									}
								}
								if (!flag4) {
									flag3 = false;
								}
							}
							if (flag3) {
								projectInfo2.setProjectNumber(projectNumber);
								projectInfo2.setOperator(Member.getRealName());
								projectInfo2.setUpdateTime(new Date());
								projectInfo2.setId(UUID.randomUUID().toString());
								transaction.insert(projectInfo2);
							}
						}
						if (transaction.commit()) {
							this.Response.put("projectId", projectInfoUpdate.getId());
							s("保存项目成功");
						} else {
							f("保存项目失败");
						}
					} else if (btn_way == ProcedureUtils.BTN_SUBMIT) {
						projectInfoUpdate.setValue(this.Request);
						projectInfoUpdate.setIsAssign("0");
						if ("1".equals(projectInfoUpdate.getProjectLevel())) {
							projectInfoUpdate.setIsFcAssign("0");
						} else {
							projectInfoUpdate.setIsFcAssign("1");
						}
						projectInfoUpdate.setPerjectType(project_state);// 资料收集
						EaoSubmitTime submitTime = new EaoSubmitTime();
						submitTime.setId(UUID.randomUUID().toString());
						submitTime.setProjectId(projectInfo.getId());
						submitTime.setProjectType("0");
						submitTime.setSubmitType("1");
						String dates = sd.format(data);
						submitTime.setDataTime(dates);
						submitTime.setOperate(Member.getRealName());
						transaction.insert(submitTime);
						transaction.update(projectInfoUpdate);

						EaoProjectInfo2 projectInfo2 = new EaoProjectInfo2();
						if (flag == true) {// 对项目基础表和资料表有值的字段进行修改时才执行备份
							DataTable dt3 = new Q("select * from eao_project_info2 where ProjectNumber = ? ",
									projectNumber).fetch();
							projectInfo2.setValue(dt.get(0));
							Boolean flag3 = true;
							Boolean flag4 = false;
							if (dt3.getRowCount() != 0) {
								for (DataRow dataRow : dt3) {
									EaoProjectInfo2 projectInfo22 = new EaoProjectInfo2();
									projectInfo22.setValue(dataRow);
									flag2 = compare(projectInfo2, projectInfo22);
									if (flag2) {
										flag4 = true;
									}
								}
								if (!flag4) {
									flag3 = false;
								}
							}
							if (flag3) {
								projectInfo2.setProjectNumber(projectNumber);
								projectInfo2.setOperator(Member.getRealName());
								projectInfo2.setUpdateTime(new Date());
								projectInfo2.setId(UUID.randomUUID().toString());
								transaction.insert(projectInfo2);
							}
						}
						if (transaction.commit()) {
							this.Response.put("projectId", projectInfoUpdate.getId());
							s("项目已提交，等待分配");
						} else {
							f("保存项目失败");
						}
					}

				} else {
					f("无权限进行此操作");
				}
			} else {
				f("项目不存在");
			}
		}

	}

	private boolean compare(EaoProjectInfo2 projectInfo23, EaoProjectInfo2 projectInfo24) {
		if (!projectInfo23.getProjectName().equals(projectInfo24.getProjectName())
				|| !projectInfo23.getBuildUnit().equals(projectInfo24.getBuildUnit())
				|| !projectInfo23.getLinkman().equals(projectInfo24.getLinkman())
				|| !projectInfo23.getTelNumber().equals(projectInfo24.getTelNumber())) {
			return true;
		} else if (StringUtil.isNotEmpty(projectInfo23.getLegalPerson())) {
			if (!projectInfo23.getLegalPerson().equals(projectInfo24.getLegalPerson())) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	/**
	 * @Title: updateIsHide
	 * @Description: 更改isHide 更改为1.
	 * @author lyz
	 * @date
	 */
	@Priv(loginType = LoginType.Member)
	public void updateIsHide() {
		Transaction transaction = new Transaction();
		List<Object> list = $A("Id");
		for (Object object : list) {
			String id = object.toString();
			Q q = new Q("update eao_project_info set IsHide = '1' where Id = ?", id);
			transaction.add(q);
		}
		if (transaction.commit()) {
			s("修改成功");
		} else {
			f("修改失败");
		}
	}

	/**
	 * @Title: findProjectByID
	 * @Description: 通过项目id查询单个项目
	 * @author wangqiangqiang
	 * @date 2018年9月17日下午4:39:36
	 */
	@Priv(loginType = LoginType.Member)
	public void findProjectByID() {
		String id = $V("Id");
		String Economy = $V("Economy");
		if (StringUtil.isNotEmpty(id)) {
			DataTable infoDt = new Q(" select * from eao_project_info where Id = ?", id).fetch();
			DataTable docDt = new Q(" select * from eao_project_doc where ProjectId = ?", id).fetch();

			DataTable publicProjectDt = new Q("select * from eao_public_project").where().in("ProjectId", id).fetch();
			DataTable buildingContentDt = new Q("select * from eao_building_content ").where().in("ProjectId", id)
					.fetch();
			DataTable equipmentDt = new Q("select * from eao_production_equipment ").where().in("ProjectId", id)
					.fetch();
			DataTable pointsDt = new Q("select * from eao_sensitive_points").where().in("ProjectId", id).fetch();
			DataTable surroundCompanyDt = new Q("select * from eao_surround_company").where().in("ProjectId", id)
					.fetch();
			DataTable appraiseDt = new Q("select * from eao_appraise").where().in("ProjectId", id)
					.append("ORDER BY AuditTime").fetch();
			DataTable publicityQuestionsDt = new Q("select * from eao_publicity_questions").where().in("ProjectId", id)
					.fetch();

			DataTable data = new Q("select * from eao_project_staff where ProjectId = ?", id).fetch();
			DataTable publicityURL = new Q("select * from eao_publicity_url where ProjectId = ?", id).fetch();

			if (infoDt.getRowCount() != 0 && docDt.getRowCount() != 0) {
				EaoProjectInfo info = new EaoProjectInfo();
				info.setValue(infoDt.get(0));
				if (StringUtils.isEmpty(info.getReportSpecialItem())) {
					info.setReportSpecialItem("[]");
				}
				if (StringUtils.isEmpty(info.getEconomyIndustryType())) {
					info.setEconomyIndustryType("[]");
				}
				if ("Economy".equals(Economy)) {
					info.setEconomyIndustryType(GBTUtil.getname(info.getEconomyIndustryType()));
				}
				if (StringUtils.isEmpty(info.getEiaAssessCategory())) {
					info.setEiaAssessCategory("[]");
				}
				EaoProjectDoc doc = new EaoProjectDoc();
				doc.setValue(docDt.get(0));

				String projectNumber = info.getProjectNumber();
				DataTable infoDt2 = new Q(
						" select * from eao_project_info2 where ProjectNumber= ? order by UpdateTime desc",
						projectNumber).fetch();
				List<EaoProjectInfo2> projectInfo2List = new LinkedList<EaoProjectInfo2>();
				for (DataRow dataRow : infoDt2) {
					EaoProjectInfo2 pt2 = new EaoProjectInfo2();
					pt2.setValue(dataRow);
					projectInfo2List.add(pt2);
				}

				List<EaoPublicProject> publicProjectList = new ArrayList<EaoPublicProject>();
				if (publicProjectDt.getRowCount() != 0) {
					for (int i = 0; i < publicProjectDt.getRowCount(); i++) {
						EaoPublicProject publicProject = new EaoPublicProject();
						publicProject.setValue(publicProjectDt.get(i));
						publicProjectList.add(publicProject);
					}
				}
				List<EaoBuildingContent> buildingContentList = new ArrayList<EaoBuildingContent>();
				if (buildingContentDt.getRowCount() != 0) {
					for (int i = 0; i < buildingContentDt.getRowCount(); i++) {
						EaoBuildingContent buildingContent = new EaoBuildingContent();
						buildingContent.setValue(buildingContentDt.get(i));
						buildingContentList.add(buildingContent);
					}
				}
				List<EaoProductionEquipment> equipmentList = new ArrayList<EaoProductionEquipment>();
				if (equipmentDt.getRowCount() != 0) {
					for (int i = 0; i < equipmentDt.getRowCount(); i++) {
						EaoProductionEquipment equipment = new EaoProductionEquipment();
						equipment.setValue(equipmentDt.get(i));
						equipmentList.add(equipment);
					}
				}

				List<EaoSensitivePoints> pointsList = new ArrayList<EaoSensitivePoints>();
				if (pointsDt.getRowCount() != 0) {
					for (int i = 0; i < pointsDt.getRowCount(); i++) {
						EaoSensitivePoints points = new EaoSensitivePoints();
						points.setValue(pointsDt.get(i));
						pointsList.add(points);
					}
				}

				List<EaoSurroundCompany> surroundCompanyList = new ArrayList<EaoSurroundCompany>();
				if (surroundCompanyDt.getRowCount() != 0) {
					for (int i = 0; i < surroundCompanyDt.getRowCount(); i++) {
						EaoSurroundCompany surroundCompany = new EaoSurroundCompany();
						surroundCompany.setValue(surroundCompanyDt.get(i));
						surroundCompanyList.add(surroundCompany);
					}
				}

				List<EaoAppraise> appraiseList = new ArrayList<EaoAppraise>();
				if (appraiseDt.getRowCount() != 0) {
					for (int i = 0; i < appraiseDt.getRowCount(); i++) {
						EaoAppraise appraise = new EaoAppraise();
						appraise.setValue(appraiseDt.get(i));
						appraiseList.add(appraise);
					}
				}

				List<EaoPublicityQuestions> publicityQuestionsList = new ArrayList<EaoPublicityQuestions>();
				if (publicityQuestionsDt.getRowCount() != 0) {
					for (int i = 0; i < publicityQuestionsDt.getRowCount(); i++) {
						EaoPublicityQuestions publicityQuestions = new EaoPublicityQuestions();
						publicityQuestions.setValue(publicityQuestionsDt.get(i));
						publicityQuestionsList.add(publicityQuestions);
					}
				}

				List<EaoProjectStaff> projectStaff = new ArrayList<>();
				for (DataRow dataRow : data) {
					EaoProjectStaff staff = new EaoProjectStaff();
					staff.setValue(dataRow);
					projectStaff.add(staff);
				}

				List<EaoPublicityURL> publicityURLlist = new ArrayList<>();
				for (DataRow dataRow : publicityURL) {
					EaoPublicityURL url = new EaoPublicityURL();
					url.setValue(dataRow);
					publicityURLlist.add(url);
				}

				if (!StringUtils.isEmpty(info.getPerjectLeader())) {
					DataTable Member = new Q(" select RealName from Ec_Member where Id = ?", info.getPerjectLeader())
							.fetch();
					this.Response.put("PerjectLeader", Member.get(0, 0));
				}
				DataTable Company = new Q(" select FullName from Crm_Company where Id = ?", info.getCompany()).fetch();
				this.Response.put("info", info);
				this.Response.put("projectStaff", projectStaff);
				this.Response.put("FullName", Company.get(0, 0));
				this.Response.put("doc", doc);
				this.Response.put("pt2List", projectInfo2List);
				$S("publicProjectList", publicProjectList);
				$S("buildingContentList", buildingContentList);
				$S("equipmentList", equipmentList);
				$S("pointsList", pointsList);
				$S("surroundCompanyList", surroundCompanyList);
				$S("appraiseList", appraiseList);
				$S("publicityQuestionsList", publicityQuestionsList);
				$S("publicityURLlist", publicityURLlist);

			} else {
				f("项目未找到");
			}
		}
	}

	/**
	 * 项目负责人章节分配
	 * 
	 * @param projectStaff
	 */
	@Priv(loginType = LoginType.Member)
	public void findByStaffs() {
		Transaction transaction = new Transaction();
		EaoProjectInfo staff = new EaoProjectInfo();
		staff.setValue(this.Request);
		DataTable dt = new Q("select * from eao_project_info  where Id = ?", staff.getId()).fetch();
		EaoProjectInfo entity = new EaoProjectInfo();
		entity.setValue(dt.get(0));
		entity.setValue(this.Request);
		transaction.update(entity);
		if (transaction.commit()) {
			s("章节分配成功");
		} else {
			f("章节分配失败");
		}
	}

	/**
	 * @Title: findWithTime
	 * @Description: 查询创建时间为半年以内且isHide为0的项目
	 * @author lyz
	 * @date
	 */
	@Priv(loginType = LoginType.Member)
	public void findWithTime() {
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		List<String> id = new ArrayList<String>();
		Q qz = new Q(" select * from eao_project_info where 1 = 1 ");
		qz.and().eq("IsHide", 0);
		qz.and().append(" PerjectTime > DATE_SUB(CURDATE(), INTERVAL 6 MONTH)");// 半年内的数据
		DataTable dataTable = qz.fetch();
		for (DataRow dataRow : dataTable) {
			EaoProjectInfo pi = new EaoProjectInfo();
			pi.setValue(dataRow);
			id.add(pi.getId());
		}
		Q q = new Q(" select * from eao_project_info where 1 = 1 ");
		q.and().eq("IsHide", 0);
		q.and().append(" PerjectTime > DATE_SUB(CURDATE(), INTERVAL 6 MONTH)");// 半年内的数据
		q.orderby("PerjectTime desc");
		DataTable projectDt = q.fetch(pageSize, pageIndex);
		List<EaoProjectInfoVo> list = new ArrayList<>();
		for (DataRow dataRow : projectDt) {
			EaoProjectInfo pi = new EaoProjectInfo();
			pi.setValue(dataRow);
			EaoProjectInfoVo vo = new EaoProjectInfoVo();
			vo.setId(pi.getId());
			vo.setPerjectTime(pi.getPerjectTime().toString());
			vo.setPerjectType(pi.getPerjectType().toString());
			vo.setProjectName(pi.getProjectName());
			vo.setProjectNumber(pi.getProjectNumber());
			vo.setBuildAddress(pi.getBuildAddress());
			vo.setContractAmount(pi.getContractAmount());
			vo.setReportType(pi.getReportType());
			if (pi.getPerjectLeader() != null) {
				vo.setPerjectLeader(pi.getPerjectLeader().toString());
			}
			DataTable dt = new Q(" select Company from Mh_Resource where Member = ? ", pi.getCreatePerson()).fetch();
			if (dt.getRowCount() != 0) {
				DataTable dt1 = new Q(" select FullName from Crm_Company where ID = ? ", dt.get(0, 0)).fetch();
				if (dt1.getRowCount() != 0) {
					vo.setFullName(dt1.get(0, 0).toString());
				}
			}

			list.add(vo);
		}
		this.Response.put("id", id);// 全部id
		this.Response.put("countProjectList", id.size());// 用于分页总条数
		this.Response.put("projectList", list);// 分页查询
	}

	/**
	 * @Title: findWithState
	 * @Description: 当前登录人正在进行的项目的状态
	 * @author lyz
	 * @date
	 */
	@Priv(loginType = LoginType.Member)
	public void findWithState() {
		String key = $V("Key");
		String order = $V("Order");
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		this.Response.put("userid", UserInfo.getID());
		this.Response.put("memberid", Member.getUID());
		String Project_name = $V("ProjectName");
		DataTable dataTable2 = new Q(" select Type , ID from Ec_Member where ID = ? ", UserInfo.getID()).fetch();
		DataTable dataTable3 = new Q("select Company , BranchInnerCode from Mh_Resource where Member = ?",
				UserInfo.getID()).fetch();
		String dataTable4 = new Q("select IsEngineer from eao_is_engineer where Member = ?", UserInfo.getID())
				.executeString();
		String Company = null;
		String BranchInnerCode = null;
		Boolean bl = false;
		if (dataTable2.getRowCount() != 0) {
			if ("Ent".equals(dataTable2.get(0, 0))) {
				Company = dataTable2.getString(0, 1);
				bl = true;
			}
		}
		if (!StringUtils.isEmpty(dataTable4)) {
			if ("1".equals(dataTable4) || "2".equals(dataTable4) || "7".equals(dataTable4)) {
				Company = dataTable3.getString(0, 0);
				bl = true;
			} else if ("3".equals(dataTable4)) {
				BranchInnerCode = new Q("select ParentInnerCode from Mh_Branch WHERE BranchInnerCode =?",
						dataTable3.getString(0, 1)).executeString();
				if ("0".equals(BranchInnerCode) || "".equals(BranchInnerCode)) {
					BranchInnerCode = dataTable3.getString(0, 1);
				}
				bl = true;
			}
		}
		if (bl) {
			Q q = new Q(" select * from eao_project_info where 1 = 1 and PerjectType <> 16 ");
			if (StringUtil.isNotEmpty(Company)) {
				q.append(" and Company = ?", Company);
			}
			if (StringUtil.isNotEmpty(BranchInnerCode)) {
				q.append(" and BranchInnerCode = ?", BranchInnerCode);
			}
			if (StringUtil.isNotEmpty(Project_name)) {
				q.append(" and ProjectName like ?", "%" + Project_name + "%");
			}
			if (StringUtil.isNotEmpty(key) && StringUtil.isNotEmpty(order)) {
				if ("normal".equals(order)) {
					q.orderby("PerjectTime desc");
				} else {
					if ("perjectTypeName".equals(key)) {
						key = "PerjectType";
					}
					q.orderby("if(Isnull(" + key + "),1,0)," + key + " " + order);
				}
			} else {
				q.orderby("PerjectTime desc");
			}
			DataTable projectDt = q.fetch(pageSize, pageIndex);
			DataTable dt = q.fetch();
			Integer count = dt.getRowCount();
			List<EaoProjectInfoVo> list = new ArrayList<>();
			if (projectDt.getRowCount() > 0) {
				for (DataRow dataRow : projectDt) {
					EaoProjectInfo projectInfo = new EaoProjectInfo();
					projectInfo.setValue(dataRow);
					EaoProjectInfoVo projectInfoVo = new EaoProjectInfoVo();
					projectInfoVo.setId(projectInfo.getId());
					projectInfoVo.setPerjectTime(projectInfo.getPerjectTime().toString());
					projectInfoVo.setPerjectType(projectInfo.getPerjectType().toString());
					projectInfoVo.setProjectName(projectInfo.getProjectName());
					projectInfoVo.setProjectNumber(projectInfo.getProjectNumber());
					projectInfoVo.setBuildAddress(projectInfo.getBuildAddress());
					projectInfoVo.setContractAmount(projectInfo.getContractAmount());
					projectInfoVo.setReportType(projectInfo.getReportType());
					projectInfoVo.setBuildUnit(projectInfo.getBuildUnit());
					list.add(projectInfoVo);
				}
				this.Response.put("count", count);
				this.Response.put("projectInfo", list);
			} else {
				f("没有正在进行的项目信息");
			}
		} else {
			DataTable dataTable = new Q(" select ProjectId from eao_project_staff where 1 = 1 and StaffName = ?",
					UserInfo.getID()).fetch();
			String Project_id = null;
			List<String> listStr = new ArrayList<>();
			if (dataTable.getRowCount() != 0) {
				for (DataRow dataRow : dataTable) {
					listStr.add(dataRow.getString(0));
					if (StringUtils.isEmpty(Project_id)) {
						Project_id = dataRow.getString(0);
					} else {
						Project_id = Project_id + "," + dataRow.getString(0);
					}
				}
			}
			Q q;
			if (dataTable.getRowCount() > 0) {
				q = new Q(" select * from eao_project_info where PerjectType <> 16 and Company = " + Member.getCompany()
						+ " and (CreatePerson = " + UserInfo.getID() + " or PerjectLeader = " + UserInfo.getID() + " ");
				q.or().in("id ", listStr);
				q.append(" ) ");
			} else {
				q = new Q(" select * from eao_project_info where PerjectType <> 16 and Company = " + Member.getCompany()
						+ " and (CreatePerson = ? or PerjectLeader = ?)", UserInfo.getID(), UserInfo.getID());
			}
			if (StringUtil.isNotEmpty(Project_name)) {
				q.append(" and ProjectName like ?", "%" + Project_name + "%");
			}
			if (StringUtil.isNotEmpty(key) && StringUtil.isNotEmpty(order)) {
				if ("normal".equals(order)) {
					q.orderby("PerjectTime desc");
				} else {
					if ("PerjectTypeName".equals(key)) {
						key = "PerjectType";
					}
					q.orderby(key + " " + order);
				}
			} else {
				q.orderby("PerjectTime desc");
			}
			DataTable projectDt = q.fetch(pageSize, pageIndex);
			DataTable dt = q.fetch();
			Integer count = dt.getRowCount();
			List<EaoProjectInfoVo> list = new ArrayList<>();
			if (projectDt.getRowCount() != 0) {
				for (DataRow dataRow : projectDt) {
					EaoProjectInfo projectInfo = new EaoProjectInfo();
					projectInfo.setValue(dataRow);
					EaoProjectInfoVo projectInfoVo = new EaoProjectInfoVo();
					projectInfoVo.setId(projectInfo.getId());
					projectInfoVo.setPerjectTime(projectInfo.getPerjectTime().toString());
					projectInfoVo.setPerjectType(projectInfo.getPerjectType().toString());
					projectInfoVo.setProjectName(projectInfo.getProjectName());
					projectInfoVo.setProjectNumber(projectInfo.getProjectNumber());
					projectInfoVo.setBuildAddress(projectInfo.getBuildAddress());
					projectInfoVo.setContractAmount(projectInfo.getContractAmount());
					projectInfoVo.setReportType(projectInfo.getReportType());
					projectInfoVo.setBuildUnit(projectInfo.getBuildUnit());
					list.add(projectInfoVo);
				}
				this.Response.put("count", count);
				this.Response.put("projectInfo", list);
			} else {
				f("没有正在进行的项目信息");
			}
		}
	}

	/**
	 * @Title: findWithTime
	 * @Description: 根据id查询正在进行的项目的状态
	 * @author lyz
	 * @date
	 */
	@Priv(loginType = LoginType.Member)
	public void findOneIdState() {
		String id = $V("Id");
		DataTable projectDt = new Q(" select Type from eao_project_info where Id = ? ", id).fetch();
		if (projectDt.getRowCount() > 0) {
			EaoProjectInfo projectInfo = new EaoProjectInfo();
			projectInfo.setValue(projectDt.get(0));
			EaoProjectInfoVo projectInfoVo = new EaoProjectInfoVo();
			projectInfoVo.setId(projectInfo.getId());
			projectInfoVo.setPerjectType(projectInfo.getPerjectType().toString());
			this.Response.put("projectInfo", projectInfoVo);
		} else {
			f("没有正在进行的项目信息");
		}
	}

	/**
	 * @Title: findAllProject
	 * @Description: 查询全部项目
	 * @author wangqiangqiang
	 * @date 2018年9月17日下午4:39:42
	 */
	@Priv(login = false)
	public void findAllProject() {
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		String Report_type = $V("ReportType");// 报告类型
		String time = $V("Time");// 时间
		String MProvince = $V("MProvince");// 省份
		String MCity = $V("MCity");// 城市
		String Project_name = $V("project_name");// 项目名
		String key = $V("key");
		String order = $V("Order");
		Q q = new Q(" select * from eao_project_info where 1 = 1 and Company = ? ", Member.getCompany());

		if ("1".equals(Report_type)) {
			q.append(" and ReportType = ?", "报告表");
		} else if ("2".equals(Report_type)) {
			q.append(" and ReportType = ?", "报告书");
		} else if ("3".equals(Report_type)) {
			q.append(" and ReportType = ?", "现状评估报告");
		} else if ("4".equals(Report_type)) {
			q.append(" and ReportType = ?", "规划环评");
		} else if ("5".equals(Report_type)) {
			q.append(" and ReportType = ?", "验收报告");
		}
		if ("1".equals(time)) {
			q.append(
					" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') BETWEEN date_sub(curdate(),interval 7 DAY) and curdate()");
		} else if ("2".equals(time)) {
			q.append(" and DATE_SUB(CURDATE(), INTERVAL 1 MONTH)<= DATE_FORMAT(PerjectTime,'%Y-%m-%d')");
		} else if ("3".equals(time)) {
			q.append(" and DATE_SUB(CURDATE(), INTERVAL 6 MONTH)<= DATE_FORMAT(PerjectTime,'%Y-%m-%d')");
		} else if ("4".equals(time)) {
			q.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') > DATE_SUB( CURDATE() , INTERVAL 12 MONTH)");
		} else if ("0".equals(time)) {
			q.append(" and 1 = 1 ");
		}
		if (StringUtil.isNotEmpty(MProvince) && StringUtil.isNotEmpty(MCity)) {
			q.append(" and BuildAddress like ?", "%" + MProvince + "%" + MCity + "%");
		}
		if (StringUtil.isNotEmpty(MProvince) && StringUtils.isEmpty(MCity)) {
			q.append(" and BuildAddress like ?", "%" + MProvince + "%");
		}
		if (StringUtil.isNotEmpty(Project_name)) {
			q.append(" and ProjectName like ?", "%" + Project_name + "%");
		}
		if (StringUtil.isNotEmpty(key) && StringUtil.isNotEmpty(order)) {
			if ("normal".equals(order)) {
				q.orderby("PerjectTime desc");
			} else {
				q.orderby(key + " " + order);
			}
		} else {
			q.orderby("PerjectTime desc");
		}
		DataTable projectDt = q.fetch(pageSize, pageIndex);
		DataTable projectDt1 = q.fetch();
		Integer count = projectDt1.getRowCount();
		List<EaoProjectInfo> list = new ArrayList<>();
		if (projectDt.getRowCount() > 0) {
			for (DataRow dataRow : projectDt) {
				EaoProjectInfo pi = new EaoProjectInfo();
				pi.setValue(dataRow);
				list.add(pi);
			}
		} else {
			list = null;
		}

		this.Response.put("countProjectList", count);// 用于分页总条数
		this.Response.put("projectList", list);// 分页查询
	}

	/**
	 * @Title: findAllProject
	 * @Description: 查询已完成全部项目
	 * @author wangqiangqiang
	 * @throws ParseException
	 * @date 2018年9月17日下午4:39:42
	 */
	@Priv(loginType = LoginType.Member)
	public void findAllEntProject() throws ParseException {
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		String startTime = $V("StartTime");// 起始时间
		String endTime = $V("EndTime");// 结束时间
		DataTable dataTable2 = new Q(" select Type , ID from Ec_Member where ID = ? ", UserInfo.getID()).fetch();
		DataTable dataTable3 = new Q("select Company from Mh_Resource where Member = ?", UserInfo.getID()).fetch();
		String dataTable4 = new Q("select IsEngineer from eao_is_engineer where Member = ?", UserInfo.getID())
				.executeString();
		String Company = null;
		Boolean bl = false;
		if (dataTable2.getRowCount() != 0) {
			if ("Ent".equals(dataTable2.get(0, 0))) {
				Company = dataTable2.getString(0, 1);
				bl = true;
			}
		}
		if (!StringUtils.isEmpty(dataTable4)) {
			if ("1".equals(dataTable4) || "2".equals(dataTable4)) {
				Company = dataTable3.getString(0, 0);
				bl = true;
			}
			DataTable table = new Q("select ParentId from eao_Position where Id = ?", dataTable4).fetch();
			if (!StringUtils.isEmpty(table)) {
				if ("1".equals(table.getString(0, 0)) || "2".equals(table.getString(0, 0))) {
					Company = dataTable3.getString(0, 0);
					bl = true;
				}
			}
		}
		Q q = new Q(" select * from eao_project_info where 1 = 1 and PerjectType = 16 ");
		List<String> Project_id = new ArrayList<>();
		if (bl) {
			q.append(" and Company = ?", Company);
		} else {
			DataTable dataTable = new Q(" select ProjectId from eao_project_staff where 1 = 1 and StaffName = ?",
					UserInfo.getID()).fetch();
			if (dataTable.getRowCount() != 0) {
				for (DataRow dataRow : dataTable) {
					Project_id.add(dataRow.getString(0));
				}
			}
			if (dataTable.getRowCount() > 0) {
				q.append(" and (CreatePerson = ? or PerjectLeader = ? ", UserInfo.getID(), UserInfo.getID());
				q.or().in(" id ", Project_id);
				q.append(" ) ");
			} else {
				q.append(" and (CreatePerson = ? or PerjectLeader = ?)", UserInfo.getID(), UserInfo.getID());
			}
		}

		if (StringUtil.isNotEmpty(startTime) && StringUtil.isNotEmpty(endTime)) {
			Date startdate = sf.parse(startTime);
			Date enddate = sf.parse(endTime);
			q.append(" and DATE_FORMAT(EntTime,'%Y-%m-%d') between ? and ?", startdate, enddate);
		} else if (StringUtil.isNotEmpty(startTime) && !StringUtil.isNotEmpty(endTime)) {
			Date startdate = sf.parse(startTime);
			q.append(" and DATE_FORMAT(EntTime,'%Y-%m-%d') between ? and ?", startdate, new Date());
		} else if (!StringUtil.isNotEmpty(startTime) && StringUtil.isNotEmpty(endTime)) {
			Date enddate = sf.parse(endTime);
			q.append(" and DATE_FORMAT(EntTime,'%Y-%m-%d') <? ", enddate);
		}
		q.orderby("PerjectTime desc");
		DataTable projectDt = q.fetch(pageSize, pageIndex);
		DataTable projectDt1 = q.fetch();
		List<EaoProjectInfo> list = new ArrayList<>();
		for (DataRow dataRow : projectDt) {
			EaoProjectInfo pi = new EaoProjectInfo();
			pi.setValue(dataRow);
			list.add(pi);
		}

		Q q1 = new Q(
				"select count(*) as Num from eao_project_info where ReportType = '报告书' and PerjectType = 16 and Company = ?",
				Member.getCompany());
		Q q2 = new Q(
				" select count(*) as Num from eao_project_info where ReportType = '报告表' and PerjectType = 16 and Company = ?",
				Member.getCompany());
		Q q3 = new Q(" select sum(ContractAmount) as Num from eao_project_info where PerjectType = 16 and Company = ? ",
				Member.getCompany());
		if (!bl) {
			DataTable dataTable = new Q(" select ProjectId from eao_project_staff where 1 = 1 and StaffName = ?",
					UserInfo.getID()).fetch();
			if (dataTable.getRowCount() > 0) {
				q1.append(" and (CreatePerson = ? or PerjectLeader = ? ", UserInfo.getID(), UserInfo.getID());
				q1.or().in(" id ", Project_id);
				q1.append(" ) ");
				q2.append(" and (CreatePerson = ? or PerjectLeader = ? ", UserInfo.getID(), UserInfo.getID());
				q2.or().in(" id ", Project_id);
				q2.append(" ) ");
				q3.append(" and (CreatePerson = ? or PerjectLeader = ? ", UserInfo.getID(), UserInfo.getID());
				q3.or().in(" id ", Project_id);
				q3.append(" ) ");
			} else {
				q1.append(" and (CreatePerson = ? or PerjectLeader = ?)", UserInfo.getID(), UserInfo.getID());
				q2.append(" and (CreatePerson = ? or PerjectLeader = ?)", UserInfo.getID(), UserInfo.getID());
				q3.append(" and (CreatePerson = ? or PerjectLeader = ?)", UserInfo.getID(), UserInfo.getID());
			}
		}
		DataTable num1 = q1.fetch();
		DataTable num2 = q2.fetch();
		DataTable num3 = q3.fetch();
		Map<String, String> numMap = new HashMap<>();

		numMap.put("bgsNum", String.valueOf(num1.get(0).getString("Num")));
		numMap.put("bgbNum", String.valueOf(num2.get(0).getString("Num")));
		numMap.put("jxNum", num3.get(0).getString("Num"));
		this.Response.put("numMap", numMap);
		this.Response.put("countProjectList", projectDt1.getRowCount());// 用于分页总条数
		this.Response.put("projectList", list);// 分页查询
	}

	/**
	 * @Title: deleteByID
	 * @Description: 删除单个项目
	 * @author wangqiangqiang
	 * @date 2018年9月17日下午4:39:49
	 */
//	@Priv(loginType = LoginType.Member)
//	public void deleteByID() {
//		String id = $V("Id");
//		if (StringUtil.isNotEmpty(id)) {
//			Transaction transaction = new Transaction();
//			DataTable deleteProjectInfoDt = new Q(" select * from eao_project_info where Id = ?", id).fetch();
//			DataTable deleteProjectInfoDt2 = new Q(" select * from eao_project_info2 where Id = ?", id).fetch();
//			DataTable deleteProjectDocDt = new Q(" select * from eao_project_doc where ProjectId = ?", id).fetch();
//			DataTable audit = new Q(" select * from eao_audit where ProjectId = ?", id).fetch();
//			DataTable content = new Q(" select * from eao_building_content where ProjectId = ?", id).fetch();
//			DataTable data = new Q(" select * from eao_data_bill where project_id = ?", id).fetch();
//			DataTable production = new Q(" select * from eao_production_equipment where ProjectId = ?", id).fetch();
//			DataTable staff = new Q(" select * from eao_project_staff where ProjectId = ?", id).fetch();
//			DataTable submit = new Q(" select * from eao_project_submit_time where ProjectId = ?", id).fetch();
//			DataTable project = new Q(" select * from eao_public_project where ProjectId = ?", id).fetch();
//			DataTable points = new Q(" select * from eao_sensitive_points where ProjectId = ?", id).fetch();
//			DataTable surround = new Q(" select * from eao_surround_company where ProjectId = ?", id).fetch();
//
//			// 如果能通过id查到
//			if (deleteProjectInfoDt.getRowCount() != 0 && deleteProjectDocDt.getRowCount() != 0) {
//				EaoProjectInfo info = new EaoProjectInfo();
//				info.setValue(deleteProjectInfoDt.get(0));
//				EaoProjectDoc doc = new EaoProjectDoc();
//				doc.setValue(deleteProjectDocDt.get(0));
//				transaction.delete(info);
//				transaction.delete(doc);
//			}
//			if (audit.getRowCount() != 0) {
//				for (DataRow dataRow : audit) {
//					EaoAudit audit2 = new EaoAudit();
//					audit2.setValue(dataRow);
//					DataTable auditreply = new Q(" select * from eao_audit_reply where AuditId = ?", audit2.getId())
//							.fetch();
//					if (auditreply.getRowCount() != 0) {
//						for (DataRow dataRow2 : auditreply) {
//							EaoAuditReply auditReply = new EaoAuditReply();
//							auditReply.setValue(dataRow2);
//							auditReply.delete();
//						}
//					}
//					audit2.delete();
//				}
//			}
//			if (content.getRowCount() != 0) {
//				for (DataRow dataRow : content) {
//					EaoBuildingContent audit2 = new EaoBuildingContent();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (data.getRowCount() != 0) {
//				for (DataRow dataRow : data) {
//					EaoDataBill audit2 = new EaoDataBill();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (production.getRowCount() != 0) {
//				for (DataRow dataRow : production) {
//					EaoProductionEquipment audit2 = new EaoProductionEquipment();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (deleteProjectInfoDt2.getRowCount() != 0) {
//				for (DataRow dataRow : deleteProjectInfoDt2) {
//					EaoProjectInfo2 audit2 = new EaoProjectInfo2();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (staff.getRowCount() != 0) {
//				for (DataRow dataRow : staff) {
//					EaoProjectStaff audit2 = new EaoProjectStaff();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (submit.getRowCount() != 0) {
//				for (DataRow dataRow : submit) {
//					EaoSubmitTime audit2 = new EaoSubmitTime();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (project.getRowCount() != 0) {
//				for (DataRow dataRow : project) {
//					EaoPublicProject audit2 = new EaoPublicProject();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (points.getRowCount() != 0) {
//				for (DataRow dataRow : points) {
//					EaoSensitivePoints audit2 = new EaoSensitivePoints();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (surround.getRowCount() != 0) {
//				for (DataRow dataRow : surround) {
//					EaoSurroundCompany audit2 = new EaoSurroundCompany();
//					audit2.setValue(dataRow);
//					audit2.delete();
//				}
//			}
//			if (transaction.commit()) {
//				s("删除项目成功");
//			} else {
//				f("删除项目失败");
//			}
//		} else {
//			f("项目未找到");
//		}
//	}

	/**
	 * @Title: getProjectNumber
	 * @Description: 创建项目编号
	 * @returnLong
	 * @author wangqiangqiang
	 * @date 2018年9月17日下午4:39:55
	 */
	@Priv(loginType = LoginType.Member)
	public String getProjectNumber() {
		Calendar now = Calendar.getInstance();
		Integer year = now.get(Calendar.YEAR);
		String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
		DataTable dt = new Q(" select NumberTypeId from eao_company_number_type where CompanyId = ? ",
				Member.getCompany()).fetch();
		String numberTypeId = "1";
		if (dt.getRowCount() > 0) {
			numberTypeId = String.valueOf(dt.get(0).getLong("NumberTypeId"));
		}
		String project_number = "";
		if ("1".equals(numberTypeId)) {
			// 查询当前日期的project_number
			Q q = new Q("select ProjectNumber from eao_project_info where");
			q.like("ProjectNumber", date);
			DataTable dataTable = q.fetch();
			Long maxID = 0L;
			// 定义一个存取当前日期标号的集合
			List<Long> idList = new ArrayList<Long>();
			if (dataTable.getRowCount() != 0) {
				for (DataRow row : dataTable) {
					idList.add(Long.valueOf(row.get(0).toString()));
				}
				// 循环获取当日最大id
				for (Long long1 : idList) {
					if (long1 > maxID) {
						maxID = long1;
					}
				}
				maxID++;
			} else {
				maxID = Long.valueOf(date + "001");
			}
			project_number = maxID.toString();
			this.Response.put("ProjectNumber", maxID);
		} else if ("2".equals(numberTypeId)) {
			String table = new Q(" select NameAbbreviation from eao_company_info where Id = ?", Member.getCompany())
					.executeString();
			if (!StringUtils.isEmpty(table)) {
//				String number = table;
				Q q = new Q("select ProjectNumber from eao_project_info where Company = ?", Member.getCompany());
				q.and().like("ProjectNumber", table + year.toString());
				DataTable dataTable = q.fetch();

				Long maxID = 0L;
				List<Long> idList = new ArrayList<Long>();
				if (dataTable.getRowCount() != 0) {
					for (DataRow row : dataTable) {
						idList.add(Long.valueOf(row.get(0).toString().substring(row.get(0).toString().length() - 4,
								row.get(0).toString().length())));
					}
					// 循环获取当日最大id
					for (Long long1 : idList) {
						if (long1 > maxID) {
							maxID = long1;
						}
					}
					maxID++;
					if (Long.toString(maxID).length() == 1) {
						project_number = table + year.toString() + "000" + maxID.toString();
					} else if (Long.toString(maxID).length() == 2) {
						project_number = table + year.toString() + "00" + maxID.toString();
					} else if (Long.toString(maxID).length() == 3) {
						project_number = table + year.toString() + "0" + maxID.toString();
					} else {
						project_number = table + year.toString() + maxID.toString();
					}
				} else {
					project_number = table + year.toString() + "0001";
				}
				this.Response.put("ProjectNumber", project_number);

			} else {
				f("本规则不可用，请在会员中心-机构基本资料-机构信息中填写机构名称缩写后使用。");
			}
		}
		return project_number;
	}

	/**
	 * @Title: findProjectVisit
	 * @Description: 项目统计
	 * @returnLong
	 * @author wangdingding
	 * @throws ParseException
	 * @date 2018年10月13日下午3:36:55
	 */
	@Priv(loginType = LoginType.Member)
	public void findProjectVisit() throws ParseException {
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		String startTime = $V("StartTime");// 起始时间
		String endTime = $V("EndTime");// 结束时间
		String MProvince = $V("MProvince");// 省份
		String MCity = $V("MCity");// 城市
		String type = $V("Type");// 状态
		String member = $V("Member");// 机构
		String companyType = $V("CompanyType");// 项目级别
		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
		Date dBegin = null;
		Date dEnd = null;
		List<String> strList = new ArrayList<>();
		FindDateUtil findDateUtil = new FindDateUtil();
		List<Map<String, String>> mapList = new ArrayList<>();
		Q q = new Q("select Company , count(*) as count from eao_project_info where 1 = 1 ");

		Q q2 = new Q(
				" select ReportType,count(ReportType) as rt from eao_project_info where 1 = 1 and ReportType is not null ");

		Q q5 = new Q(" select DATE_FORMAT(PerjectTime,'%Y-%m-%d') ,count(Id) as rt from eao_project_info where 1 = 1 ");
		if (StringUtil.isNotEmpty(startTime) && StringUtil.isNotEmpty(endTime)) {
			dEnd = sd.parse(endTime);
			dBegin = sd.parse(startTime);
			strList = findDateUtil.findDates(dBegin, dEnd);
			q.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between ? and ?", startTime, endTime);
			q2.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between ? and ?", startTime, endTime);
			q5.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between ? and ?", startTime, endTime);
		} else if (StringUtil.isNotEmpty(startTime) && !StringUtil.isNotEmpty(endTime)) {
			Date dtEnd = new Date();
			endTime = sd.format(dtEnd);
			dEnd = sd.parse(endTime);
			dBegin = sd.parse(startTime);
			strList = findDateUtil.findDates(dBegin, dEnd);
			q.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between ? and ?", startTime, endTime);
			q2.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between ? and ?", startTime, endTime);
			q5.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between ? and ?", startTime, endTime);
		} else if (!StringUtil.isNotEmpty(startTime) && StringUtil.isNotEmpty(endTime)) {
			dEnd = sd.parse(endTime);
			strList = findDateUtil.findDates(dBegin, dEnd);
			q.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between DATE_SUB( ? , INTERVAL 1 MONTH) and ? ", endTime,
					endTime);
			q2.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between DATE_SUB( ? , INTERVAL 1 MONTH) and ? ",
					endTime, endTime);
			q5.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') between DATE_SUB( ? , INTERVAL 1 MONTH) and ? ",
					endTime, endTime);
		} else if (!StringUtil.isNotEmpty(startTime) && !StringUtil.isNotEmpty(endTime)) {
			dEnd = new Date();
			strList = findDateUtil.findDates(dBegin, dEnd);
			q5.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') > DATE_SUB( CURDATE() , INTERVAL 1 MONTH) ");
		}
		if (StringUtil.isNotEmpty(MProvince) && StringUtil.isNotEmpty(MCity)) {
			q.append("and BuildAddress like ?", "%" + MProvince + "%" + MCity + "%");
			q2.append("and BuildAddress like ?", "%" + MProvince + "%" + MCity + "%");
			q5.append("and BuildAddress like ?", "%" + MProvince + "%" + MCity + "%");
		}
		if (StringUtil.isNotEmpty(type)) {
			q.and().eq("ReportType", type);
			q2.and().eq("ReportType", type);
			q5.and().eq("ReportType", type);
		}
		if (StringUtil.isNotEmpty(member)) {
			q.and().eq("Company", member);
			q2.and().eq("Company", member);
			q5.and().eq("Company", member);
		}
		if (StringUtil.isNotEmpty(companyType)) {
			q.and().eq("ProjectLevel", companyType);
			q2.and().eq("ProjectLevel", companyType);
			q5.and().eq("ProjectLevel", companyType);
		}
		q.append(" group by Company ");
		q2.append(" group by ReportType ");
		q5.append(" group by DATE_FORMAT(PerjectTime,'%Y-%m-%d') ");
		q5.append(" order by PerjectTime desc ");
		DataTable dt = q.fetch(pageSize, pageIndex);
		DataTable dt2 = q2.fetch();
		DataTable dt5 = q5.fetch();
		if (dt.getRowCount() > 0) {
			List<EaoProjectInfoVo> list = new ArrayList<>();
			List<Map<String, String>> listmap = new ArrayList<>();
			List<String> strs = new ArrayList<>();
			for (DataRow dataRow : dt) {
				EaoProjectInfoVo vo = new EaoProjectInfoVo();
				DataTable dt1 = new Q(
						" select FullName , AddTime,Province , City , District , Street from Crm_Company where ID = ? ",
						dataRow.get(0)).fetch();
				if (dt1.getRowCount() != 0) {
					CrmCompany company = new CrmCompany();
					company.setValue(dt1.get(0));

					vo.setFullName(company.getFullName());
					vo.setPerjectTime(company.getAddTime().toString());
					vo.setBuildAddress(dt1.get(0, 2).toString() + dt1.get(0, 3).toString() + dt1.get(0, 4).toString()
							+ dt1.get(0, 5).toString());
				}
				DataTable dtt = new Q(
						" select ReportType,count(ReportType) as rt from eao_project_info where 1 = 1 and ReportType is not null and Company = ? GROUP BY ReportType",
						dataRow.get(0)).fetch();
				String reportType = null;
				for (DataRow dr : dtt) {
					if (reportType == null) {
						reportType = dr.getString(0) + dr.getString(1);
					} else {
						reportType += dr.getString(0) + dr.getString(1);
					}
				}
				vo.setPerjectType(dataRow.getString(1));
				vo.setReportType(reportType);
				list.add(vo);
			}
			DataTable dt3 = q.fetch();
			Integer countProject = null;
			for (DataRow dataRow : dt3) {
				if (StringUtils.isEmpty(countProject)) {
					countProject = dataRow.getInt(1);
				} else {
					countProject += dataRow.getInt(1);
				}
			}
			this.Response.put("countProject", countProject);
			this.Response.put("countProjectList", dt3.getRowCount());// 用于分页总条数
			this.Response.put("projectList", list);// 分页查询

			Map<String, String> map1 = new HashMap<>();
			for (DataRow dataRow : dt5) {
				for (String str : strList) {
					String AddTime = null;
					String countAddTime = "0";
					AddTime = dataRow.get(0).toString();
					countAddTime = dataRow.get(1).toString();
					if (str.equals(AddTime)) {
						map1.put("date", countAddTime);
						map1.put(AddTime, countAddTime);
						strs.add(AddTime);
					}
				}
			}

			for (String str : strList) {
				Map<String, String> map = new HashMap<>();
				Boolean lean = true;
				String countAddTime = "0";
				for (String map2 : strs) {
					if (str.equals(map2)) {
						lean = false;
					}
				}
				if (lean) {
					map.put("date", str);
					map.put("count", countAddTime);
					listmap.add(map);
				} else {
					map.put("date", str);
					map.put("count", map1.get(str));
					listmap.add(map);
				}
			}

			Map<String, String> map = new HashMap<>();
			for (DataRow string : dt2) {
				String Report_id = string.getString(0);
				if (StringUtil.isNotEmpty(Report_id)) {
					map.put(Report_id, string.getString(1));
				}
			}
			DataTable dtCount = new Q("select count(*) as count from eao_project_info ").fetch();
			map.put("项目总数", dtCount.get(0, 0).toString());
			mapList.add(map);
			this.Response.put("count", dtCount.get(0, 0));
			this.Response.put("countAddTime", listmap);// 数量——时间（折线图，柱状图）
			this.Response.put("mapList", mapList);// 项目个数，报告书，报告表个数

		} else {
			f("查询的项目不存在");
		}
	}

	// 获取字符串中指定字符出现的次数
	public static int search(String str, String strRes) {
		int n = 0;// 计数器
		int index = 0;// 指定字符的长度
		index = str.indexOf(strRes);
		while (index != -1) {
			n++;
			index = str.indexOf(strRes, index + 1);
		}

		return n;
	}

	/**
	 * 根据二级账户id查询项目记录
	 */
	@Priv(loginType = LoginType.Member)
	public void findTwoProject() {
		int a = 0;
		String Create_person = String.valueOf(Member.getUID());// 当前操作人id
		if (Create_person != null) {
			int pageSize = this.Request.getInt("PageSize");
			if (pageSize == 0) {
				pageSize = 10;
			}
			int pageIndex = this.Request.getInt("PageIndex");
			DataTable projectDt = new Q(
					" select m.Fullname,ec.Username,ProjectName,PerjectTime from eao_project_info as e,Mh_Resource as m,Ec_Member as ec where date_sub(curdate(), interval 6 month) <= date(PerjectTime) and e.CreatePerson = m.Member and m.Member = ec.Id and e.CreatePerson = ? ",
					Create_person).fetch(pageSize, pageIndex);
			DataTable projectNum = new Q(
					"select count(1) as num from eao_project_info where date_sub(curdate(), interval 6 month) <= date(PerjectTime)")
							.fetch();
			List<EaoProjectInfoVo> projectInfoVo = new ArrayList<EaoProjectInfoVo>();
			if (projectDt.getRowCount() > 0) {
				for (DataRow dataRow : projectDt) {
					EaoProjectInfoVo projectInfo = new EaoProjectInfoVo(dataRow.getString

					("ProjectName"), dataRow.getString("PerjectTime"), dataRow.getString

					("Fullname"), dataRow.getString("Username"));
					projectInfoVo.add(projectInfo);
				}

				if (projectNum.getRowCount() != 0) {
					for (DataRow dataRow : projectNum) {
						a = dataRow.getInt("num");
					}
					this.Response.put("countNum", a);
				} else {
					$F("查询半年内的项目记录数量失败");
				}
				this.Response.put("projectInfoVoList", projectInfoVo);
			} else {
				$F("查询项目记录失败");
			}
		} else {
			$F("id为空");
		}

	}

	@Priv(loginType = LoginType.Member)
	public Boolean getProjectName() {
		String project_id = $V("ProjectId");
		String project_name = $V("ProjectName");
		Long uesrId = Member.getUID();
		DataTable dt = new Q(" select Company from Mh_Resource where Member = ? ", uesrId).fetch();
		if (dt.getRowCount() != 0 || Member.getType().equals("Ent")) {
			Q q = new Q(" select * from eao_project_info where 1 = 1 ");
			if (Member.getType().equals("Ent")) {
				q.append("and Company = ? ", uesrId);
			} else {
				q.append("and Company = ? ", dt.get(0, 0));
			}
			if (StringUtil.isNotEmpty(project_id)) {
				q.append(" and id <> ?", project_id);
			}
			DataTable dataTable = q.fetch();
			Boolean is = true;
			if (dataTable.getRowCount() > 0) {
				for (DataRow dataRow : dataTable) {
					EaoProjectInfo info = new EaoProjectInfo();
					info.setValue(dataRow);
					if (project_name.equals(info.getProjectName())) {
						is = false;
					}
				}
				if (is) {
					s("项目名可以使用");
					return true;
				} else {
					f("项目名已存在,请更换新的项目名");
					return false;
				}
			} else {
				s("项目名可以使用");
				return true;
			}
		} else {
			f("请联系管理员分配所属机构");
			return false;
		}
	}

	// 对获取的id json串进行完善
	public static void getIds(String[] ids, String[] tempid) {
		for (int i = 0; i < ids.length; i++) {
			for (int j = 0; j < tempid.length; j++) {
				if (i == j) {
					ids[i] = tempid[j];
				}
			}
		}
		for (int i = 0; i < ids.length; i++) {
			if (ids[i] == null) {
				ids[i] = "";
			}
		}
	}

	/**
	 * 取得给定汉字串的首字母串,即声母串
	 * 
	 * @param str 给定汉字串
	 * @return 声母串
	 */
	public String getAllFirstLetter(String str) {
		if (str == null || str.trim().length() == 0) {
			return "";
		}

		String _str = "";
		for (int i = 0; i < str.length(); i++) {
			_str = _str + this.getFirstLetter(str.substring(i, i + 1));
		}

		return _str;
	}

	/**
	 * 取得给定汉字的首字母,即声母
	 * 
	 * @param chinese 给定的汉字
	 * @return 给定汉字的声母
	 */
	public String getFirstLetter(String chinese) {
		if (chinese == null || chinese.trim().length() == 0) {
			return "";
		}
		chinese = this.conversionStr(chinese, "GB2312", "ISO8859-1");

		if (chinese.length() > 1) // 判断是不是汉字
		{
			int li_SectorCode = (int) chinese.charAt(0); // 汉字区码
			int li_PositionCode = (int) chinese.charAt(1); // 汉字位码
			li_SectorCode = li_SectorCode - 160;
			li_PositionCode = li_PositionCode - 160;
			int li_SecPosCode = li_SectorCode * 100 + li_PositionCode; // 汉字区位码
			if (li_SecPosCode > 1600 && li_SecPosCode < 5590) {
				for (int i = 0; i < 23; i++) {
					if (li_SecPosCode >= li_SecPosValue[i] && li_SecPosCode < li_SecPosValue[i + 1]) {
						chinese = lc_FirstLetter[i];
						break;
					}
				}
			} else // 非汉字字符,如图形符号或ASCII码
			{
				chinese = this.conversionStr(chinese, "ISO8859-1", "GB2312");
				chinese = chinese.substring(0, 1);
			}
		}

		return chinese;
	}

	/**
	 * 字符串编码转换
	 * 
	 * @param str           要转换编码的字符串
	 * @param charsetName   原来的编码
	 * @param toCharsetName 转换后的编码
	 * @return 经过编码转换后的字符串
	 */
	private String conversionStr(String str, String charsetName, String toCharsetName) {
		try {
			str = new String(str.getBytes(charsetName), toCharsetName);
		} catch (UnsupportedEncodingException ex) {
			System.out.println("字符串编码转换异常：" + ex.getMessage());
		}
		return str;
	}

	@Priv(loginType = LoginType.Member)
	public void reportType() {
		String id = $V("Id");
		String reportType = $V("ReportType");
		if (!StringUtils.isEmpty(reportType)) {
			DataTable dt = new Q("select *  from eao_project_info where Id= ? ", id).fetch();
			EaoProjectInfo projectInfoUpdate = new EaoProjectInfo();
			projectInfoUpdate.setValue(dt.get(0));// 数据库的值
			if (!reportType.equals(projectInfoUpdate.getReportType())) {
				Transaction t = new Transaction();
				Q q = new Q(" UPDATE eao_project_info SET ReportChapter = NULL where Id = ?", id);
				Q q1 = new Q(" UPDATE eao_project_staff SET ReportChapter = NULL where ProjectId = ?", id);
				t.add(q);
				t.add(q1);
				if (t.commit()) {
					s("操作成功");
				} else {
					f("操作失败");
				}
			}
		}
	}
}
